var contestId = getUrlVar("contestId");
var loginUrl = "/front/detailcontest/login";
document.getElementById("problem").innerHTML = "<a href='problem?contestId="+ contestId +"'>Problem</a>";
document.getElementById("status").innerHTML = "<a href='status?contestId="+ contestId +"'>Status</a>";
document.getElementById("rank").innerHTML = "<a href='rank?contestId="+ contestId +"'>Rank List</a>";
document.getElementById("discuss").innerHTML = "<a href='discuss?contestId="+ contestId +"'>Discuss</a>";
document.getElementById("printer").innerHTML = "<a href='printer?contestId="+ contestId +"'>Printer</a>";
var info = document.getElementById("info");
if (getName(localName) != null) {
    info.innerHTML = 'Hi! <span class="name-hits">' + getName(localName) + '</span>'
                    + '<br /> <span class="name-hits" style="color: cornflowerblue" onclick="logout()" >logout</span>';
    $.ajax({
        type: "GET",
        url : ojurl + "/contest/token",
        beforeSend: function (request) {
            appendToken(request)
        },
        data: {"contestId": contestId},
        timeout: 5000,
        success: function(result) {
            if (result.code == HttpStatus.UNAUTHORIZED) {
                removeName(tokenName);
                removeName(localName);
                window.location.href = "./login?contestId="+contestId;
            }
        }
    })
}
else {
    var button = info.getElementsByTagName("button")[0];
    button.onclick = function() {
        window.location.href = "./login?contestId="+contestId;
    }
    var url = window.location.pathname;
    if (url != loginUrl) {
        window.location.href = loginUrl + "?contestId=" + contestId;
    }
}